﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using tcm.entity;
using tcm.utils;

namespace tcm.request.System
{
    public class SysLoginRequest
    {
        /// <summary>
        /// 用户名
        /// </summary>
        public string user_name { get; set; }

        /// <summary>
        /// 用户密码
        /// </summary>
        public string password { get; set; }

        ///// <summary>
        ///// 验证码
        ///// </summary>
        //public string code { get; set; }

        ///// <summary>
        ///// 验证码key
        ///// </summary>
        //public string? uuid { get; set; }

        /// <summary>
        /// 登录IP
        /// </summary>
        public string? login_IP { get; set; }
    }

    public class LoginUser
    {
        /// <summary>
        /// 用户id
        /// </summary>
        public long user_id { get; set; }

        //账户登录名
        public string user_name { get; set; }

        //token
        public string token { get; set; }

        /// <summary>
        /// 角色
        /// </summary>
        public List<SysRole> roles { get; set; }

        /// <summary>
        /// 角色集合
        /// </summary>
        public List<string> roleIds { get; set; }

        /// <summary>
        /// 验证码key
        /// </summary>
        public bool isAdmin { get; set; }

        /// <summary>
        /// 权限
        /// </summary>
        public List<string> permissions { get; set; }


        public LoginUser()
        {
        }

        public LoginUser(SysUser user, List<SysRole> roles, List<string> permissions)
        {
            this.user_id = user.id;
            this.user_name = user.user_name;
            this.roleIds = roles?.Select(f => f.role_key).ToList();
            this.permissions = permissions;
            this.roles=roles;
            this.isAdmin =roles.Any(r=>r.role_key.Contains(GlobalConstant.AdminRole));
            this.token=user.token;
        }

    }

    public class LoginCaptcha
    {
        /// <summary>
        /// 验证码key
        /// </summary>
        public string uuid { get; set; }

        /// <summary>
        /// 图片base64Str
        /// </summary>
        public string img { get; set; }

    }
}
